using AutoMapper;
using B.S.Data.MES.API.Applications.BaseData.Command.MaterialGroupCommand;
using B.S.Domain.BasicData.MaterialManagement.MaterialGroups;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.BaseData.CommandHandlers.MaterialGroupCommandHandlers
{
    public class UpdateMaterialGroupCommandHandler : IRequestHandler<UpdateMaterialGroupCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<Material_group> _materialGroupRepository;
        private readonly IMapper _mapper;

        public UpdateMaterialGroupCommandHandler(IBaseRepository<Material_group> materialGroupRepository, IMapper mapper)
        {
            _materialGroupRepository = materialGroupRepository;
            _mapper = mapper;
        }

        public async Task<APIRequst<int>> Handle(UpdateMaterialGroupCommand request, CancellationToken cancellationToken)
        {
            var su= _mapper.Map<Material_group>(request);
            su.UpdateTime = DateTime.Now;
            su.CreateTime = DateTime.Now;
            await _materialGroupRepository.Update(su);
            return new APIRequst<int> 
            {
                Code=RequstCode.成功,
                Msg=RequstCode.成功.ToString(),
            };
        }
    }
}